testsuite: Redo listbox sort test
authorMatthias Clasen <mclasen@redhat.com>
Sat, 9 May 2020 02:39:51 +0000 (22:39 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Tue, 12 May 2020 02:21:39 +0000 (22:21 -0400)
This test was relying on gtk_container_forall returning
the visual (ie sorted) order of children, while iterating
with the widget dom api gives the insertion order.

Instead of using gtk_container_forall, use
gtk_list_box_row_get_index to reconstruct the visual
order.

testsuite/gtk/listbox.c

index c36c855faabf088b6c746cf9feaf9b04e2b34e59..0c646bd5d333abed319288a77d596c876b3e8d80 100644 (file)
@@ -24,18 +24,22 @@ static void
 check_sorted (GtkListBox *list)
 {
   GtkWidget *row, *label;
-  gint n1, n2;
+  int res[100];
+  int index, value;
+  int i;
 
-  n2 = n1 = 0;
   for (row = gtk_widget_get_first_child (GTK_WIDGET (list));
        row != NULL;
        row = gtk_widget_get_next_sibling (row))
     {
-      n1 = n2;
+      index = gtk_list_box_row_get_index (GTK_LIST_BOX_ROW (row));
       label = gtk_list_box_row_get_child (GTK_LIST_BOX_ROW (row));
-      n2 = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (label), "data"));
-      g_assert_cmpint (n1, <=, n2);
+      value = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (label), "data"));
+      res[index] = value;
     }
+
+  for (i = 1; i < 100; i++)
+    g_assert (res[i - 1] <= res[i]);
 }
 
 static void